//
//  AccountViewController+AccountViewController.m
//  NiuNiuPacking
//
//  Created by shaoting on 14-9-3.
//  Copyright (c) 2014年 Reseek. All rights reserved.
//

#import "AccountViewController.h"
#import "Toast+UIView.h"
#import "NSString+SBJSON.h"
#import "ASIFormDataRequest.h"

@interface AccountViewController ()<ASIHTTPRequestDelegate>

@end

@implementation AccountViewController

- (IBAction)showMenu
{
    [self.frostedViewController presentMenuViewController];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
    
    NSURL *url = [NSURL URLWithString:p_get_user_balanceURL];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
    [request setHTTPMethod:@"POST"];
    NSString *str = [NSString stringWithFormat:@"&token=%@",delegate.currentUser.token];
    NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    NSData *received = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *responseStr = [[NSString alloc]initWithData:received encoding:NSUTF8StringEncoding];
    NSDictionary *jsonDict = [responseStr JSONValue];
    int errnum = [jsonDict[@"errno"] intValue];
    if(errnum == 0) {
        self.txtzhye.text = [NSString stringWithFormat:@"￥%@.00", [jsonDict[@"balance_cash"]description]];
        self.txtktx.text = [NSString stringWithFormat:@"￥%@.00", [jsonDict[@"balance_cash"]description]];
        self.txtbonus.text = [NSString stringWithFormat:@"￥%@.00", [jsonDict[@"balance_bonus"]description]];
        self.txtbycz.text = [NSString stringWithFormat:@"￥%@.00", [jsonDict[@"chongzhi_amount"]description]];
        self.txtbytx.text = [NSString stringWithFormat:@"￥%@.00", [jsonDict[@"tixian_amount"]description]];
        self.txtbysr.text = [NSString stringWithFormat:@"￥%@.00", [jsonDict[@"income_amount"]description]];
        self.txtbyzc.text = [NSString stringWithFormat:@"￥%@.00", [jsonDict[@"outcome_amount"]description]];
    } else {
        [self.view makeToast:jsonDict[@"errmsg"]
                    duration:1.0
                    position:@"bottom"];
    }
}

- (IBAction)btnChongzhi:(id)sender {
    [self.view makeToast:@"敬请期待"
                duration:1.0
                position:@"bottom"];
}

- (IBAction)btnTixian:(id)sender {
    [self.view makeToast:@"敬请期待"
                duration:1.0
                position:@"bottom"];
}
@end
